//
//  BKMyOrderMainCell.m
//  bestkeep
//
//  Created by Mr. Wu on 16/12/5.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderMainCell.h"
#import "BKMyOrderGetDataFromNetWork.h"
#import "BK_OD_Tool.h"
#import "BK_My_Order_CollectionViewCell.h"
#import "BKMyOrderCollectionFootViewAndHederView.h"
#import "BKMyOrderRecommendCell.h"
#import "BKMyOrderCellHeaderView.h"
#import "BKMyOrderCellFootView.h"
#import "MJRefresh.h"
#import "HUD.h"
#import "Mediator+BKGD.h"
#import "UIView+ParentController.h"
#import "BKMyOrderDetailController.h"
#import "BKMyOrderAlert.h"
#import "BKMyOrderChooseGoEvaluatingVC.h"
#import "BK_my_EvaluationOfDryingVC.h"
#import "Mediator+BKOrder.h"
#import "BKMyOrderCheckLogisticsController.h"
#import "BKMyOrderRetuanGoodDetailController.h"
#import "BKShowBottomTiPMessageView.h"
#import "ExceptionView.h"
#import "BK_My_Order_Model.h"

#import "BK_OD_Color.h"


#define Pagesize  @"20"
#define Tag_Receive_GoodS  100
#define Tag_Delete_Order   200
@interface BKMyOrderMainCell ()
<
    UIAlertViewDelegate,
    UICollectionViewDelegate,
    UICollectionViewDataSource,
    UICollectionViewDelegateFlowLayout,
    BK_OrderFooter_Delegate,
    CancelOrderDelegate
>

@property(nonatomic,strong) NSMutableArray *marr_OrderData;
@property(nonatomic,copy  ) NSString *str_CurrntPage;
@property(nonatomic,copy  ) NSString *str_Order_id;//订单id,删除,确认,会用到;
@property(nonatomic,copy  ) NSString *str_Order_Number;//订单号;
@property(nonatomic,strong) BK_My_Order_rows_itemList_Model *model_Order_rows_itemList_detail;
@property(nonatomic,strong) ExceptionView *exceptionView;
@property(nonatomic,strong) BK_My_Order_rows_Model *model_Order_rows;

@end
@implementation BKMyOrderMainCell
-(NSMutableArray *)marr_OrderData{
    if (!_marr_OrderData) {
        _marr_OrderData = [NSMutableArray array];
    }
    return _marr_OrderData;
}
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
    
}
-(void)initView{
    
    UICollectionViewFlowLayout *laout = [[UICollectionViewFlowLayout alloc]init];
    laout.scrollDirection = UICollectionViewScrollDirectionVertical;
    _collectionview  = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) collectionViewLayout:laout];
    _collectionview.backgroundColor = kOrderLightGrey2;
    _collectionview.delegate = self;
    _collectionview.dataSource = self;
    _collectionview.bounces = YES;
    [self addSubview:_collectionview];
    [self setUpRefresh];
    [self.collectionview.mj_header beginRefreshing];
}



#pragma mark  设置刷新
-(void)setUpRefresh{
    BKRefreshGifHeader *headerRefresh = [BKRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(BK_Order_Update_Header)];
    self.collectionview.mj_header = headerRefresh;
    BKMyOrderFooterAutoReferesh *footer = [BKMyOrderFooterAutoReferesh footerWithRefreshingTarget:self refreshingAction:@selector(BK_Order_Refresh_Footer)];
    self.collectionview.mj_footer = footer;
    self.collectionview.mj_footer.hidden = YES;
}

#pragma mark 下拉刷新
-(void)BK_Order_Update_Header{
    [self updateData_checkNetWorking];
}

#pragma mark 上拉加载
-(void)BK_Order_Refresh_Footer{
    NSInteger page = [self.str_CurrntPage integerValue];
    page++;
    self.str_CurrntPage = [NSString stringWithFormat:@"%ld",(long)page];
    [self addData_checkNetWorking];
}

#pragma mark 上拉刷新-检查网络
-(void)addData_checkNetWorking {
    
    RequestReachabilityStatus status = [RequestManager reachabilityStatus];
    switch (status) {
        case RequestReachabilityStatusReachableViaWiFi:
        case RequestReachabilityStatusReachableViaWWAN: {
            [self BK_addData_FromNetWork];
        }
            break;
        default: {
            [HUD dismiss];
            [self.collectionview.mj_footer endRefreshing];
            [BKShowBottomTiPMessageView showMessage:@"请连接到网络，再试一次"];
        }
            break;
    }
}


#pragma mark 上拉加载更多的数据
-(void)BK_addData_FromNetWork{
   [BKMyOrderGetDataFromNetWork GetOrderData:self.str_number pagesize:Pagesize pageno:self.str_CurrntPage Success:^(NSArray *OrderArray) {
       
       NSArray * Arr_sectionModel=[self create_Arr_SectionModel:OrderArray];
       [self.collectionview.mj_footer endRefreshing];
       if (!Arr_sectionModel.count) {
           self.collectionview.mj_footer.hidden = YES;
           return ;
       }
       NSInteger cout = [Pagesize integerValue];
       if ((Arr_sectionModel.count %cout) != 0) {
           self.collectionview.mj_footer.hidden = YES;
       }
       [self.marr_OrderData addObjectsFromArray:Arr_sectionModel];
       [self.collectionview reloadData];
   } failure:^(NSError *error) {
       [self.collectionview.mj_footer endRefreshing];
       [BKShowBottomTiPMessageView showMessage:error.localizedDescription];
   } currentPage:^(NSDictionary *Page) {
       self.str_CurrntPage = Page[@"currentPage"];
   }];
  
}


#pragma mark  下拉刷新-检查网络
-(void)updateData_checkNetWorking {
    
    self.collectionview.mj_footer.hidden=NO;
    
    RequestReachabilityStatus status = [RequestManager reachabilityStatus];
    switch (status) {
        case RequestReachabilityStatusReachableViaWiFi:
        case RequestReachabilityStatusReachableViaWWAN: {
            [self BK_getData_FromNetWork];
            
        }
            break;
            
        default: {
            [HUD dismiss];
            
            [self.marr_OrderData  removeAllObjects];
            [self.collectionview  reloadData];
            if (self.marr_OrderData.count<1) {
                self.collectionview.mj_footer.hidden=YES;
            }
            
            
            [self.collectionview.mj_header endRefreshing];
            [self.collectionview.mj_footer endRefreshing];
            
            self.exceptionView = [ExceptionView exceptionViewWithType:ExceptionCodeTypeNoNetwork];
            ExceptionViewAction *action = [ExceptionViewAction actionWithType:ExceptionCodeTypeNoNetwork handler:^(ExceptionViewAction *action) {
                [self.exceptionView dismiss];
                self.exceptionView = nil;
                [self updateData_checkNetWorking];
            }];
            [self.exceptionView addAction:action];
            [self.exceptionView showInView:self];
            
        }
            break;
    }
}
/*
 * 构建SectionModel
 */
-(NSArray *)create_Arr_SectionModel:(NSArray *)OrderArray{
    NSArray *array;
    NSMutableArray *SectionArray = [NSMutableArray array];//section数组
    array= [BK_My_Order_rows_Model mj_objectArrayWithKeyValuesArray:OrderArray];
    
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        BK_My_Order_rows_Model *model = obj;
        BK_My_Order_SectionModel *section = [BK_My_Order_SectionModel crete_Order_SetionWithModel:model];
        [SectionArray addObject:section];
        
    }];
    
    return SectionArray;
}

#pragma mark 下拉刷新    更新数据
-(void)BK_getData_FromNetWork{
    self.collectionview.mj_footer.hidden = YES;
    if (self.exceptionView) {//先消失,防止重复;
        [self.exceptionView dismiss];
        self.exceptionView = nil;
    }
    [BKIndicationView showInView:self.collectionview];
    [BKMyOrderGetDataFromNetWork GetOrderData:self.str_number pagesize:Pagesize pageno:@"1" Success:^(NSArray *OrderArray) {
        
        [self.collectionview.mj_header endRefreshing];
        [BKIndicationView dismiss];
    
        NSArray *SectionArray=[self create_Arr_SectionModel:OrderArray];
        NSInteger cout = [Pagesize integerValue];
        if ((SectionArray.count %cout) != 0) {//数据已经加载完了    刷不出数据了
            self.collectionview.mj_footer.hidden = YES;
        }else{
            self.collectionview.mj_footer.hidden = NO;
        }

        [self.marr_OrderData removeAllObjects];
        [self.marr_OrderData addObjectsFromArray:SectionArray];
        [self.collectionview reloadData];

        if (self.marr_OrderData .count<1) {
            self.collectionview.mj_footer.hidden = YES;
            self.exceptionView = [ExceptionView exceptionViewWithType:ExceptionCodeTypeNoData];
            ExceptionViewAction *action = [ExceptionViewAction actionWithType:ExceptionCodeTypeNoData handler:^(ExceptionViewAction *action) {
                [self.exceptionView dismiss];
                self.exceptionView = nil;
                [self updateData_checkNetWorking];
            }];
            NSString *title;
            switch ([self.str_number integerValue]) {
                    
                case 1:
                    title = @"暂无待付款商品";
                    break;
                case 2:
                    title = @"暂无待发货商品";
                    break;
                case 3:
                    title = @"暂无待收货商品";
                    break;
                case 401:
                    title = @"暂无待评价商品";
                    break;
                    
                default:
                    title = @"暂无订单商品";
                    break;
            }
            self.exceptionView.contentLabel.text = @"";
            self.exceptionView.contentLabel.hidden=YES;
            [self.exceptionView addAction:action];
            [self.exceptionView showInView:self];
        }
        
    }failure:^(NSError *error) {
        [BKIndicationView dismiss];
        
        ExceptionCodeType errorType;
        if (error.code == -1009) {
            errorType = ExceptionCodeTypeNoNetwork;
        }else if (error.code == -1001){
            errorType = ExceptionCodeTypeRequestFailed;
        }else if (error.code == 502 || error.code == 404){
            errorType = ExceptionCodeTypeServerError;
        }else{
            errorType = ExceptionCodeTypeFailedToLoad;
        }
        
        self.exceptionView = [ExceptionView exceptionViewWithType:errorType];
        ExceptionViewAction *action = [ExceptionViewAction actionWithType:errorType handler:^(ExceptionViewAction *action) {
            [self.exceptionView dismiss];
            self.exceptionView = nil;
            [self BK_getData_FromNetWork];
        }];
        
        [self.exceptionView addAction:action];
        [self.exceptionView showInView:self];

        [self.collectionview.mj_header endRefreshing];
        
    } currentPage:^(NSDictionary *Page) {
         self.str_CurrntPage = Page[@"currentPage"];
    }];
}

#pragma mark CollectionView Datasouce Delegate;
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return self.marr_OrderData.count;
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    BK_My_Order_SectionModel *model = self.marr_OrderData[section];
    return model.OrderCells.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    BK_My_Order_SectionModel *section = self.marr_OrderData[indexPath.section];
    BK_My_Order_CellModel*row = section.OrderCells[indexPath.row];
    [self.collectionview registerClass:NSClassFromString(row.className) forCellWithReuseIdentifier:row.reuseIdentifier];
   
    BK_My_Order_CollectionViewCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:row.reuseIdentifier forIndexPath:indexPath];
    cell.BK_My_Order_Cell_Delegate = self;
    for (UIView *view in cell.contentView.subviews) {
        if ([view isKindOfClass:[BK_My_Order_DetaiCell class]]) {
            [view removeFromSuperview];
        }
    }
    if(!cell) {
        cell = [[NSClassFromString(row.className) alloc] init];
    }
    if (SystemVersion < 8.0) {
        SEL fillData = @selector(fillData:);
        if ([cell respondsToSelector:fillData]) {
            NSString *className = NSStringFromClass([BKMyOrderEmptyCell class]);
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
            if ([row.className isEqualToString:className]) {
                [cell performSelector:fillData withObject:self.str_number];
            }else{
                [cell performSelector:fillData withObject:row];
            }
        }
    }
    return cell;
    
}

-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
    if (SystemVersion >= 8.0) {
        BK_My_Order_SectionModel *section = self.marr_OrderData[indexPath.section];
        BK_My_Order_CellModel*row = section.OrderCells[indexPath.row];
        
        BK_My_Order_CollectionViewCell *Cell = (BK_My_Order_DetaiCell *)cell;
        SEL fillData = @selector(fillData:);
        if ([cell respondsToSelector:fillData]) {
            NSString *className = NSStringFromClass([BKMyOrderEmptyCell class]);
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
            if ([row.className isEqualToString:className]) {
                [Cell performSelector:fillData withObject:self.str_number];
            }else{
                [Cell performSelector:fillData withObject:row];
            }
        }
    }
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    BK_My_Order_SectionModel *Sectionmodel = self.marr_OrderData[indexPath.section];
    BK_My_Order_CellModel *cellmodle = Sectionmodel.OrderCells[indexPath.row];
    NSString *orderCell = NSStringFromClass([BK_My_Order_DetaiCell class]);
    NSString *recommendcell = NSStringFromClass([BKMyOrderRecommendCell class]);
    if ([cellmodle.className isEqualToString:orderCell]) {
        BKMyOrderDetailController *Con = [BKMyOrderDetailController new];
        Con.ordermodel  = cellmodle.model_Order_rows;
        Con.Order_no = Sectionmodel.model_Order_rows.order_no;
        UIViewController *Controll = [UIView BKcurrentViewController];
         [Controll.navigationController pushViewController:Con animated:YES];
        Con.reloadData = ^(NSString *remove){
            [self BK_getData_FromNetWork];
        };
    }
    if ([cellmodle.className isEqualToString:recommendcell]) {
        BkMyOrderRecommendModel *model = cellmodle.recommendModel;
        UIViewController *vc =[[Mediator sharedInstance]BKGD_goodsDetailViewController:model.goodsId saleTypes:nil];
        [[UIView BKcurrentViewController].navigationController pushViewController:vc animated:YES];
        
    }

}

#pragma mark collection的头试图和尾试图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

    BK_My_Order_SectionModel *section = self.marr_OrderData[indexPath.section];
    UICollectionReusableView *reusableView = [[UICollectionReusableView alloc] init];
    
    [self.collectionview registerClass:NSClassFromString(section.headViewClassName) forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:section.headReuseIdentifier];
    
    [self.collectionview registerClass:NSClassFromString(section.footViewClassName) forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:section.footReuseIdentifier];
  
    if (kind == UICollectionElementKindSectionHeader) {
        BKMyOrderCollectionFootViewAndHederView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:section.headReuseIdentifier forIndexPath:indexPath];
        headerView.sectionDelegate = self;
        SEL fillData = @selector(fillData:);
        if ([headerView respondsToSelector:fillData]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"[]
            [headerView performSelector:fillData withObject:section];
        }

        reusableView = headerView;
    }else if (kind == UICollectionElementKindSectionFooter) {
        BKMyOrderCollectionFootViewAndHederView*footView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:section.footReuseIdentifier forIndexPath:indexPath];
        footView.sectionDelegate = self;
        SEL fillData = @selector(fillData:);
        if ([footView respondsToSelector:fillData]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
            [footView performSelector:fillData withObject:section];
        }

        reusableView = footView;
    }
   
    return reusableView;
}

- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath{
    BK_My_Order_SectionModel *section = self.marr_OrderData[indexPath.section];
    if (SystemVersion >= 8.0){
    if (elementKind ==UICollectionElementKindSectionHeader ) {
        BKMyOrderCollectionFootViewAndHederView *header = (BKMyOrderCollectionFootViewAndHederView*)view;
        SEL fillData = @selector(fillData:);
        if ([header respondsToSelector:fillData]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"[]
            [header performSelector:fillData withObject:section];
        }
        
    }
    if (elementKind == UICollectionElementKindSectionFooter) {
        BKMyOrderCollectionFootViewAndHederView *foot = (BKMyOrderCollectionFootViewAndHederView*)view;
        SEL fillData = @selector(fillData:);
        if ([foot respondsToSelector:fillData]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
            [foot performSelector:fillData withObject:section];
        }
    }
    }
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    BK_My_Order_SectionModel *sc = self.marr_OrderData[section];
    CGFloat height = sc.headerhHeight;
    return CGSizeMake(ScreenWidth, height);
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    BK_My_Order_SectionModel *sc = self.marr_OrderData[section];
    CGFloat height = sc.footerHeight;
    return CGSizeMake(ScreenWidth, height);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    BK_My_Order_SectionModel *model   = self.marr_OrderData[section];
    return model.minimumLine;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 0,0,0);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;{
    return 0.45;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    BK_My_Order_SectionModel *section = self.marr_OrderData[indexPath.section];
    BK_My_Order_CellModel *item = section.OrderCells[indexPath.item];
    return item.ItemSize;
}

/*
 * footer的代理
 */
#pragma mark==================BK_OrderFooter_Delegate====================
-(void)BK_OrderFooter_Delegate_Click:(NSString *)str AndModel:(BK_My_Order_SectionModel *)model{
    BK_My_Order_rows_Model *Ordermodel = model.model_Order_rows;
    self.model_Order_rows = Ordermodel;
    self.str_Order_Number = Ordermodel.order_no;
    BK_My_Order_CellModel *cellmodel = model.OrderCells[0];
    
    self.model_Order_rows_itemList_detail = cellmodel.DetailModel;
    
    self.str_Order_id = Ordermodel.order_id;
    
    if ([str isEqualToString:@"删除订单"]) {
        [self goto_Delete_Order];
    }
    if ([str isEqualToString:@"确认收货"]) {
        [self goto_ConfrimRecive_Order];
    }
    if ([str isEqualToString:@"去评价"]) {
        [self goto_Evaluation_Order];
    }
    if ([str isEqualToString:@"取消订单"]) {
        [self goto_CanCel_Order];
    }
    if ([str isEqualToString:@"去付款"]) {
        [self goto_Pay_Order];
    }
    if ([str isEqualToString:@"退换货"]) {
        [self goto_Return_Goods];
    }
    if ([str isEqualToString:@"查看物流"]) {
        [self goto_Logistics];
    }
    if ([str isEqualToString:@"延长收货"]) {
       // [self gotoProlongReciveGoods];
    }

}


#pragma mark==================删除订单====================
-(void)goto_Delete_Order{
    UIAlertView *alertVA = [[UIAlertView alloc]initWithTitle:@"确认删除订单？" message:@"\n删除之后可以从电脑端订单回收站恢复" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertVA.tag = Tag_Delete_Order;
    [alertVA show];
}
#pragma mark==================确认收货====================
-(void)goto_ConfrimRecive_Order{
    UIAlertView *alertVA = [[UIAlertView alloc]initWithTitle:@"\n确认收货？\n"  message:nil  delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertVA.tag=Tag_Receive_GoodS;
    [alertVA show];
    
}
#pragma mark========================delegate【确认收货】【删除订单】====================
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    //确认收货;
    if (alertView.tag == Tag_Receive_GoodS) {
               NSString *btnTitle = [alertView buttonTitleAtIndex:buttonIndex];
        if ([btnTitle isEqualToString:@"取消"]) {
        }else if ([btnTitle isEqualToString:@"确定"] ) {
           [BKMyOrderGetDataFromNetWork ConfrimReceiveGoodsWithOrderID:self.str_Order_id Status:^(NSString *str) {
               if ([str isEqualToString:@"1"]) {
                   [HUD showSuccessMessage:@"确认收货成功"];
                   [self BK_getData_FromNetWork];
               }
           } ];
             }
    //删除订单;
    }else if(alertView.tag == Tag_Delete_Order){
        NSString *btnTitle = [alertView buttonTitleAtIndex:buttonIndex];
        if ([btnTitle isEqualToString:@"取消"]) {
        }else if ([btnTitle isEqualToString:@"确定"] ) {
           [BKMyOrderGetDataFromNetWork DeleteOrderdataWithOrderID:self.str_Order_id Status:^(NSString *str) {
              
               if ([str isEqualToString:@"1"]) {
                     [HUD showSuccessMessage:@"删除订单成功"];
                   [self BK_getData_FromNetWork];
               }else{
                   [HUD showMessage:str];
               }
           }];
        }
    }
}

#pragma mark==================去评价====================
-(void)goto_Evaluation_Order{
   
    if (self.model_Order_rows.item_list.count>1) {
        BKMyOrderChooseGoEvaluatingVC *vc = [[BKMyOrderChooseGoEvaluatingVC alloc]init];
        vc.ordId = self.str_Order_id;
         [[UIView BKcurrentViewController].navigationController pushViewController:vc animated:YES];
    }else{
        BK_my_EvaluationOfDryingVC *vc = [[BK_my_EvaluationOfDryingVC alloc] init];
        vc.goodsId = self.model_Order_rows_itemList_detail.goods_id;
        vc.order_id = self.str_Order_id;
        vc.order_item_id  = self.model_Order_rows_itemList_detail.order_item_id;
        vc.img = self.model_Order_rows_itemList_detail.goods_img;
        vc.name = self.model_Order_rows_itemList_detail.goods_name;
        vc.reloadData = ^(NSString *remove){
           [self.collectionview.mj_header beginRefreshing];
        };
       [[UIView BKcurrentViewController].navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark==================取消订单====================
-(void)goto_CanCel_Order{
  BKMyOrderAlert *alertView= [BKMyOrderAlert makeViewWithMask:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    alertView.delegate = self;
}

-(void)cancelOrderbuttonClick:(NSString *)str{
    [BKMyOrderGetDataFromNetWork CancelOrder:self.str_Order_id reason:str Status:^(NSString *str) {
        if ([str isEqualToString:@"1"]) {
            [HUD showSuccessMessage:@"取消订单成功"];
            [self BK_getData_FromNetWork];
        }
        else{
            [HUD showMessage:str];
        }
    }];
}


#pragma mark==================去付款====================
-(void)goto_Pay_Order{
    NSString *globalStatus = self.model_Order_rows.channel_type;
    if ([globalStatus isEqualToString:@"02"]) {
        globalStatus = @"1";
    }else{
        globalStatus = @"0";
    }
    NSString *order_no = self.model_Order_rows.order_no;
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:globalStatus,@"globalStatus",order_no,@"orderNumber", nil];
    UIViewController *con = [[Mediator sharedInstance]BKOrder_paymentViewControllerWithParameter:dic];
    [[UIView BKcurrentViewController].navigationController pushViewController:con animated:YES];
}

#pragma mark==================退换货====================
-(void)goto_Return_Goods{
    BKMyOrderRetuanGoodDetailController *con = [BKMyOrderRetuanGoodDetailController new];
    con.orderModel = self.model_Order_rows;
    [[UIView BKcurrentViewController].navigationController pushViewController:con animated:YES];
    
}

#pragma mark==================查看物流====================
-(void)goto_Logistics{
    BKMyOrderCheckLogisticsController *con = [BKMyOrderCheckLogisticsController new];
    con.orderNo = self.str_Order_Number;
    [[UIView BKcurrentViewController].navigationController pushViewController:con animated:YES];
}
#pragma mark ------延长收货
-(void)gotoProlongReciveGoods{
    
}

@end



























